package com.ningxia.water.mapper;

import com.ningxia.water.entity.TsApplicantWell;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ningxia.water.vo.out.ApplicantWellVo;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author hz
 * @since 2021-05-14
 */
public interface TsApplicantWellMapper extends BaseMapper<TsApplicantWell> {

    /**
     * 获取用户对应的所有机井id
     * @param applicantId
     * @return
     */
    @Select("select well_id from ts_applicant_well where applicant_id = #{applicantId}")
    List<Integer> getWellIdsByApplicant(Integer applicantId);

    /**
     * 获取用水户对应的所有机井信息
     * @param applicantId
     * @return
     */
    @Select("SELECT\n" +
            "\twi.well_id,\n" +
            "\twi.well_name,\n" +
            "\twi.well_code,\n" +
            "\twi.well_type \n" +
            "FROM\n" +
            "\tts_applicant_well aw\n" +
            "\tLEFT JOIN ts_well_info wi ON aw.well_id = wi.well_id \n" +
            "WHERE\n" +
            "\taw.applicant_id = #{applicantId}")
    List<ApplicantWellVo> getWellInfos(Integer applicantId);

}
